﻿/*版权声明
 * 
 * 本 河北大学管理学院信息管理系网站 由
 * 河北大学 信管团队 开发
 * 如有任何疑问请联系开发人员
 * 
 * 项目开发者：朱胜贤、孙旭峰、水亚亚、张文元、项玥、吕芳、吴凡、谢静、李亚慧
 * 
 * 如有任何疑问请联系：河北大学信管团队
 * QQ：196396337
 * Email:zagelover@163.com
 * HomePage：http://sxgzs.com/
 * 
 * CopyRight (c) 河北大学信管团队 2010~2020
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Download_Info_Manage : System.Web.UI.Page
{
    /// <summary>页面加载事件
    /// 	<remark>2010-10-30 河北大学信管团队-朱胜贤 </remark>
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Uid"] == null)
        {
            Response.Redirect("AD_Login.aspx");
            return;
        }
        lblMessage.Text = "";
        if (!IsPostBack)
        {
            bing_GV();
        }
    }
    /// <summary>为空间绑定数据--GridView
    /// <remarks>2010-10-30 河北大学信管团队-朱胜贤</remarks>
    /// </summary>
    public void bing_GV()
    {
        string sql = "select * from Download_Info order by dowUpdateTime desc";
        GV.DataSource = DataAccess.GetDataTable(sql, null);
        GV.DataKeyNames =new string[] {"dowID"};
        GV.DataBind();
    }
    /// <summary>响应GridView事件——创建数据行时
    /// <remarks>2010-10-30 河北大学信管团队-朱胜贤</remarks>
    /// </summary>
    protected void GV_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;this.style.backgroundColor='#6699ff'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
    }
    /// <summary>响应GridView事件——删除记录时
    /// 	<remark>2010-10-30 河北大学信管团队-朱胜贤 </remark>
    /// </summary>
    protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string downUrl = "";
        string downID="";
        string sql = "select dowID,dowUrl from Download_Info where dowID=@dowID";
        //string sql2 = "select * from Download_Info where dowID=@dowID";
        SqlParameter[] para = { new SqlParameter("@dowID",SqlDbType.Int) };
        para[0].Value = GV.DataKeys[e.RowIndex][0].ToString();
        SqlDataReader sdr = DataAccess.GetReader(sql, para);
        if (sdr.HasRows)
        {
            while (sdr.Read())
            {
                downUrl = sdr["dowUrl"].ToString();
                downID = sdr["dowID"].ToString();
                string sql2 = "delete from Download_Info where dowID = " + Convert.ToInt32(downID);
                //SqlParameter[] para2 = { new SqlParameter("@dowID2", SqlDbType.Int) };
                //para[0].Value = GV.DataKeys[e.RowIndex][0].ToString();
                if (DataAccess.ExecuteSQL(sql2,null))
                {
                    //string sql2 = "delete from Download_Info where dowID=@dowID2";
                    //SqlParameter[] para2 = {new SqlParameter("@dowID2",SqlDbType.Int };
                    string UpfileName = Server.MapPath(downUrl).ToString();
                    if (System.IO.File.Exists(UpfileName))
                    {
                        System.IO.File.Delete(UpfileName);
                    }
                    lblMessage.Text = "删除数据成功";
                    bing_GV();
                }
                else
                {
                    lblMessage.Text = "删除数据失败";
                }
            }
        }
    }
    /// <summary>响应GridView事件——切换页码时
    /// 	<remark>2010-10-30 河北大学信管团队-朱胜贤 </remark>
    /// </summary>
    protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GV.PageIndex = e.NewPageIndex;
        bing_GV();
    }
}